#include "widget.h"
#include "ui_widget.h"

#include <QCheckBox>
#include <QDebug>
#include <QLabel>
#include <QPushButton>
#include <QString>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QLabel* label = new QLabel("你选择的内容是：", this);
    QCheckBox* checkbox1 = new QCheckBox("吃饭", this);
    QCheckBox* checkbox2 = new QCheckBox("睡觉", this);
    QCheckBox* checkbox3 = new QCheckBox("打豆豆", this);
    QPushButton* btn = new QPushButton("确定", this);

    checkbox1->setObjectName("checkbox_eat");
    checkbox2->setObjectName("checkbox_sleep");
    checkbox3->setObjectName("checkbox_play");


    label->move(200,200);
    checkbox1->move(200, 250);
    checkbox2->move(200, 300);
    checkbox3->move(200, 350);
    btn->move(200, 400);

    connect(btn, &QPushButton::clicked, this, &Widget::btnSlot);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::btnSlot()
{
    QString str;
    QCheckBox* eat = findChild<QCheckBox*>("checkbox_eat");
    QCheckBox* sleep = findChild<QCheckBox*>("checkbox_sleep");
    QCheckBox* play = findChild<QCheckBox*>("checkbox_play");

    if(eat->isChecked())
    {
        str += eat->text();
    }
    if(sleep->isChecked())
    {
        str += sleep->text();
    }
    if(play->isChecked())
    {
        str += play->text();
    }

    qDebug() << str;
}
